package leetcode;

public class Q0036 {
    public boolean isValidSudoku(char[][] board) {
        boolean[][] row = new boolean[9][9];
        boolean[][] column = new boolean[9][9];
        boolean[][] block = new boolean[9][9];

        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board.length; j++) {
                if (board[i][j] != '.') {
                    int num = board[i][j] - '0';
                    if (row[i][num - 1] || column[j][num - 1] || block[i / 3 * 3 + j / 3][num - 1]) return false;
                    row[i][num - 1] = true;
                    column[j][num - 1] = true;
                    block[i / 3 * 3 + j / 3][num - 1] = true;
                }
            }
        }

        return true;
    }
}
